package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-08-12
 * Time: 16:01
 */
class MyThread extends Thread{ //创建一个新的类, 让这个类继承标准库的Thread类
    @Override
    public void run(){  //线程的入口函数
        while(true){
            System.out.println("hello thread!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo1 {
    public static void main(String[] args) throws InterruptedException{
        // 1. 创建 Thread 的实例
        Thread t = new MyThread();
        t.start(); //启动线程, 这里会自动调用run函数
        while(true) {
            System.out.println("hello main");
            Thread.sleep(1000);
            }
        }

}
